#include<iostream>
#include<string.h>
using namespace std;
typedef struct node{
	int data;
	struct node *lchild;
	struct node *rchild;
}BTNode;
typedef struct node *BTree;
 BTree createBT(int  *post,int *in,int n);
void Preorder(BTree BT);
int main()
{
	BTree BT;
	int n,i,j;
	cin>>n;
	int  s1[n],s2[n];
	for(i=0;i<n;i++)
	cin>>s1[i];
	for(j=0;j<n;j++)
	cin>>s2[j];
	BT=createBT(s1,s2,n);
    Preorder(BT);
	return 0;
 } 
 BTree createBT(int *post,int *in,int n)
 {
 	BTree b;
 	int *p;
 	int k;
 	if(n<=0)
 	return NULL;
 	b=new BTNode;
 	b->data=*(post+n-1);
 	for(p=in;p<n+in;p++)
 	if(*p==b->data)
 	break;
 	k=p-in;
 	b->lchild=createBT(post,in,k);
 	b->rchild=createBT(post+k,p+1,n-k-1);
 	return b;
 }
void Preorder(BTree BT)
{
	static int i=-1;
	if(BT!=NULL)
	{
		i++;
		if(i==0)
		cout<<"Preorder:";
		cout<<" "<<BT->data;
		Preorder(BT->lchild);
		Preorder(BT->rchild);
	}
}
